var imgLoaded = true;
$(function () {

    var startNum = 0;   // ÿ������ʱ��ͼƬ�ӵڼ��ſ�ʼ���ء�
    var limitNum = 10;   // ÿ������ʱ��ͼƬ���ص�������

    var Ourl = httpHost + "/Money/getBillList?start=" + startNum + "&limit=" + limitNum + "&type=" + $(".entrust_category ul li").eq(0).attr("type") + "&select_time=" + $(".entrust_category ul li").eq(1).attr("type");
    loadArts(Ourl, startNum);

    $(window).scroll(function () {
        if (($(window).height() + document.body.scrollTop)+10 >= document.body.scrollHeight) {
            if (imgLoaded) {
                startNum += limitNum;
                Ourl = httpHost + "/Money/getBillList?start=" + startNum + "&limit=" + limitNum + "&type=" + $(".entrust_category ul li").eq(0).attr("type") + "&select_time=" + $(".entrust_category ul li").eq(1).attr("type");
                imgLoaded = false;
                loadArts(Ourl, startNum);
            };
        }
    });

    $(".loading_style").show();

    $(".entrust_category ul li").tap(function(){
        //isLogin();
        var category = $(this).attr("category");
        $('.opa_background').show();
        $(".entrust_category_news").show();
        var categoryText = 0;
        $(".entrust_category_news ul").each(function(){
            categoryText = $(this).attr("categoryText");
            if(category == categoryText){
                $(".entrust_category_news ul").hide();
                $(this).show();
            }
        });
        $(".entrust_category_news ul li").off("tap").on("tap",function(){
            var categoryText = $(this).parent().attr("categoryText");
            var thistext = $(this).text();
            var type = $(this).attr("type");
            $(this).parent().find("li").css("background","none");
            $(this).css("background","url('../img/rightYes.png') 680px 35px no-repeat");
            $('.opa_background').hide();
            $(".entrust_category_news").hide();
            var category = 0;
            $(".entrust_category ul li").each(function(){
                category = $(this).attr("category");
                if(categoryText == category){
                    $(this).text(thistext).attr("type",type).css("list-style","none");
                }
            });

            $(".money_news dl").remove();
            startNum = 0;
            var Ourl = httpHost + "/Money/getBillList?start=" + startNum + "&limit=" + limitNum + "&type=" + $(".entrust_category ul li").eq(0).attr("type") + "&select_time=" + $(".entrust_category ul li").eq(1).attr("type");
            loadArts(Ourl, startNum);
            $(".artfin_no_style").hide();
            $(".load-more").hide();
            $(".loading_style").show();

        });
    });

    $('.opa_background').tap(function(){
        var entrust_category_news = $(".entrust_category_news").css("display");
        if(entrust_category_news != "none"){
            $('.opa_background').hide();
            $(".entrust_category_news").hide();
        }
    });

});

function appendLi(data) {

    if(data.more == 0 || data.more == null){
        $(".load-more").hide();
    }else{
        $(".load-more").show();
        imgLoaded = true;
    }

    if(data.count == 0){
        $(".artfin_no_style").show();
    }else{
        for (var i = 0; i < data.list.length; i++) {
            var jsondata = data.list[i];
            if(jsondata.type == 2){
                var Dhtml = '<dl><dt class="color_style">'+ jsondata.amount +'</dt><dd>'+ jsondata.name +'</dd><dd><time>'+ jsondata.created +'</time></dd></dl>';
            }else{
                if(jsondata.type_id == 1){
                    if(jsondata.remark != ""){
                        var Dhtml = '<dl style="height: 150px;"><dt>'+ jsondata.amount +'</dt><dd>'+ jsondata.name +'</dd><dd><span style="font-size: 24px;color: #888;">('+ jsondata.remark +')</span></dd><dd><time>'+ jsondata.created +'</time></dd></dl>';
                    }else{
                        var Dhtml = '<dl><dt>'+ jsondata.amount +'</dt><dd>'+ jsondata.name +'</dd><dd><time>'+ jsondata.created +'</time></dd></dl>';
                    }
                }else{
                    var Dhtml = '<dl><dt>'+ jsondata.amount +'</dt><dd>'+ jsondata.name +'</dd><dd><time>'+ jsondata.created +'</time></dd></dl>';
                }
            }
            $(".money_news").append(Dhtml);
        }
    }

}